package jvm.jtacck.db.records;


/**
 * @author Chris Gamble
 * 
 *         Represents a Hospital record in the database. A hospital has an ID
 *         number, a name, and an address.
 */
public class Hospital extends Record {
    
    private static final long serialVersionUID = -1878531611795940701L;
    public final String name;
    public final String address;
    public final int hospital_id;

    /**
     * Constructs a new Hospital
     * 
     * @param hid
     *            The hospital_id of this hospital
     *            NON-NULLABLE
     * @param name
     *            The name of this hospital
     * @param address
     *            The address of this hospital Must be of the form:
     *            "<<Address1>>, <<Address2>>, <<City>>, <<State>>, <<ZipCode>>"
     */
    public Hospital(int hid, String name, String address) {
        super();
        this.hospital_id = hid;
        this.name = name;
        this.address = address;
    }
    
    @Override
    public boolean equals(Object o){
        if (o instanceof Hospital) {
            Hospital other = (Hospital) o;
            boolean x =
                   (hospital_id == other.hospital_id) &&
                   checkString(name, other.name) &&
                   checkString(address, other.address);
            return x;
        }
        return false;
    }
    
    public boolean checkString(String s1, String s2) {
        if (s1 == null) {
            return s2 == null;
        }else {
            return s1.equals(s2);
        }
    }
    
    @Override
    public int hashCode() {
        return hospital_id + name.hashCode() + 
        address.hashCode();
    }
    
    public String toString() {
        return hospital_id + ": " + name + ", " + address + ".";
    }
}